<template>
	<view>
		<!-- 背景圖 -->
		<image class="backImage" src="https://app.yycjkb.cn/index/fujiajia/矩形111.png" mode="widthFix"></image>

		<view class="container">
			<!-- 用戶信息 -->
			<view class="user-info">
				<view class="user-info-left">
					<image v-if="userInfo.luohan==1" class="user-info-image" src="/static/luohan.png" mode="aspectFill">
					</image>
					<image v-else class="user-info-image" :src="userInfo.avatar || '/static/default_avatar.png'"
						mode=""></image>
					<view class="user-info-name" v-if="hasLogin">
						<view class="name">{{userInfo.nickname}}</view>
						<view class="info">
							<view class="uid">UID:{{userInfo.id}} <text class="user-copy" @tap.stop="copy">复制</text>
							</view>
							<view class="contribute">贡献值:{{userInfo.contribute}}</view>
							<view class="contribute" v-if="(userInfo.user_level==2 || userInfo.user_level==3)">
								流量券：{{userInfo.contribution}}</view>
						</view>
					</view>

					<view class="user-info-name" v-if="!hasLogin">
						<button class="login-btn" @tap="jumpTo('/pages/my/login', 'inside', false)"
							v-if="!hasLogin">点击登录</button>
					</view>
				</view>
				<view class="user-info-right" v-if="userInfo.user_level==3">
					<!-- https://app.yycjkb.cn/index/fujiajia/xunzhang.png -->
					<image class="medal" :src="userInfo.user_fee_level" mode=""></image>
					<view class="post">
						<image class="gradient" src="https://app.yycjkb.cn/index/fujiajia/jianbian.png" mode="">
						</image>
						<view>业务员
						</view>
					</view>
				</view>
			</view>

			<!-- 錢包 -->
			<view class="money-bag">
				<image class="money-bag-image" src="https://app.yycjkb.cn/index/fujiajia/jianbianback.png" mode="">
				</image>
				<view class="money-bag-content">
					<view class="money-content-left">
						<view class="">
							<image src="#" mode=""></image>
							<text class="shopTitle">商家中心专享</text>
						</view>
						<view class="">
							<image src="#" mode=""></image>
							解锁所有权益
						</view>
					</view>
				</view>
			</view>

			<!-- 小助手 -->
			<view class="small-assistant">
				<view class="assistant-content">

					<view class="assistant-item" @tap="addApply()">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/12.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							商户进件
						</view>
					</view>
					<view class="assistant-item" v-for="item in assistant">
						<view class="assistant-image-box">
							<image :src="item.icon" mode=""></image>
						</view>
						<view class="assistant-item-title">
							{{item.title}}
						</view>
					</view>
					<view class="assistant-item" @tap="addGoods()">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/saoma@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							发布商品
						</view>
					</view>

					<view class="assistant-item" @tap="toprint()">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/797@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							添加打印机播报器
						</view>
					</view>
					<view class="assistant-item" @tap="tospeaker()">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/806@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							添加云音箱
						</view>
					</view>
					<view class="assistant-item" @tap="chainJoin()" v-if="shop.is_chain_shop==1">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/824@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							申请连锁
						</view>
					</view>
					<view class="assistant-item" @tap="chainJoin()" v-if="shop.is_chain_shop==1">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/863@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							加入连锁
						</view>
					</view>
					<view class="assistant-item" @tap="chainUser()" v-if="shop.is_chain_shop==1">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/864@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							收款账号
						</view>
					</view>
					<view class="assistant-item" @tap="applyalliance()">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/901@2x.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							申请联盟
						</view>
					</view>
					<view class="assistant-item" @tap="joinalliance()">
						<view class="assistant-image-box">
							<image src="https://app.yycjkb.cn/index/fujiajia/12.png" mode=""></image>
						</view>
						<view class="assistant-item-title">
							加入联盟
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部tabbar -->
		<tabBar :selectIndex="selectIndex"></tabBar>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import MyHomeSlide from "@/components/MyHomeSlide";
	import api from '@/api/';
	import shop from '@/api/shop.js';
	import user from '@/api/user.js';
	import tabBar from "../components/tabBar/index.vue"
	export default {
		components: {
			tabBar
		},
		data() {
			return {
				slides: [],
				isHome: 'isShop',
				shop: {
					wx_mchid: ''
				},
				selectIndex: 2,
				assistant: [{
						icon: '/static/icons/contract.png',
						title: '签约码',
						url: '/pages/shipment/Qrcode'
					}, {
						icon: '/static/icons/config.png',
						title: '活动配置',
						url: '/pages/my/shop/setting'
					}, {
						icon: '/static/icons/collect.png',
						title: '收款码',
						url: '/pages/my/shop/qrcode'
					},
					{
						icon: '/static/icons/collect.png',
						title: '扫码付',
						url: '/pages/home/scan/scan'
					},
					{
						icon: '/static/icons/edit.png',
						title: '修改资料',
						url: '/pages/my/shop/profile'
					},
					{
						icon: '/static/icons/statistics.png',
						title: '营收统计',
						url: '/pages/my/shop/order'
					},
					{
						icon: '/static/icons/benefit.png',
						title: '商家收益',
						url: '/pages/my/shop/rebate'
					},
					{
						icon: '/static/icons/fans.png',
						title: '商家粉丝',
						url: '/pages/my/shop/fans'
					},
					// {
					// 	icon: '/static/icons/progress.png',
					// 	title: '商户进件',
					// 	url: '/pages/shipment/index'
					// },



					{
						icon: '/static/icons/user.png',
						title: '消费用户',
						url: '/pages/my/shop/users'
					},



					// {
					// 	icon: '/static/icons/product.png',
					// 	title: '发布商品',
					// 	url: '/pages/publish-product/publish-product'
					// },

				]
			};
		},
		components: {
			MyHomeSlide
		},
		computed: {
			...mapState(['config', 'hasLogin', 'userInfo']),
		},
		onLoad() {
			this.loadIndex();
		},
		methods: {
			toprint() {
				uni.navigateTo({
					url: '/pages/my/shop/wifiprint?spid=' + this.shop.id
				})
			},
			tospeaker() {
				uni.navigateTo({
					url: '/pages/my/shop/speaker?spid=' + this.shop.id
				})
			},
			joinalliance() {
				uni.navigateTo({
					url: '/pages/my/allianceList/allianceList'
				})
			},
			chain() {
				uni.navigateTo({
					url: '/pages/my/shop/chain'
				})
			},
			chainJoin() {
				uni.navigateTo({
					url: '/pages/my/shop/chain_join'
				})
			},
			chainUser() {
				uni.navigateTo({
					url: '/pages/my/shop/chain_user'
				})
			},
			applyalliance() {
				let that = this;
				uni.showModal({
					title: '申请联盟',
					content: '',
					editable: true, //是否显示输入框
					placeholderText: '请输入联盟名称', //输入框提示内容
					confirmText: '确认',
					cancelText: '取消',
					success: (res) => {
						if (res.confirm) {
							if (!res.content) {
								return this.toast('联盟名称不能为空')
							}
							that.changealliance(res.content)
							console.log('输入的内容：', res.content);

						}
					}
				});
			},
			changealliance(alliance_name) {
				user.changealliance({
					alliance_name: alliance_name
				}).then(res => {
					uni.hideLoading();
					// if (res.code === 1) {
					// this.user_level = res.data.user.user_level
					return this.toast(res.msg)
					// }
				})
			},
			// 返回上一页
			goBack() {
				// 这里的代码可以根据使用的框架进行修改
				// 在 uniapp 中，使用 uni.navigateBack()
				uni.navigateBack();
			},
			async copy() {
				uni.setClipboardData({
					data: this.shop.short_name.toString()
				}).then(res => {
					const [error, data] = res;
					if (!error) {
						this.toast('复制成功');
					} else {
						console.error(error);
					}
				});
			},
			navigateTo(url) {
				if (url) {
					uni.navigateTo({
						url: url
					});
				}
			},
			addApply() {
				if (this.shop.applyId > 0) {
					uni.navigateTo({
						url: '/pages/shipment/index?id=' + this.shop.applyId
					});
				} else {
					uni.navigateTo({
						url: '/pages/shipment/index'
					});
				}

			},
			addGoods() {
				// #ifdef H5
				location.href = 'https://www.yycjkb.cn/index/user/login.html'
				// #endif

				// #ifdef APP-PLUS

				plus.runtime.openUrl('https://www.yycjkb.cn/index/user/login.html')

				// #endif
			},
			async loadIndex() {
				var type = 'shop';
				api.index({
					type: type
				}).then(res => {
					if (res.code === 1) {
						this.slides = res.data.list;
					} else {
						this.toast(res.msg);
					}
				});

				shop.index().then(res => {
					if (res.code === 1) {
						this.shop = res.data.shop;
					} else {
						this.toast(res.msg);
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>
	.user-copy {
		font-size: 12px;
		letter-spacing: 0;
		background: #F8ACA9;
		color: #fff;
		border-radius: 20px;
		padding: 2px 6px;
		margin-left: 10px;
	}

	.login-btn {
		margin-left: 20px;
		font-size: 30rpx;
		background: transparent;
		border: none;
		color: #fff;
		outline: none;
		padding: 0;

		// width: 30%;
		&::after {
			display: none;
		}
	}

	.backImage {
		width: 100%;
		position: absolute;
		left: 0%;
	}

	.container {
		padding-top: 140rpx;
		padding-bottom: 178rpx;
		width: 690rpx;
		margin: auto;
		position: relative;

		.user-info {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.user-info-left {
				display: flex;

				.user-info-image {
					width: 137rpx;
					height: 137rpx;
					border-radius: 100rpx;
				}

				.user-info-name {
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					padding: 10rpx 20rpx;

					.info {
						color: #666666;
						font-size: 24rpx;
						line-height: 140%;
					}
				}
			}

			.user-info-right {
				text-align: center;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.medal {
					width: 80rpx;
					height: 58rpx;
					margin-bottom: -5rpx;
				}

				.post {
					width: 98rpx;
					height: 38rpx;
					position: relative;
					color: #fff;
					padding: 10rpx 0;

					.gradient {
						width: 100%;
						height: 100%;
						position: absolute;
						left: 50%;
						transform: translate(-50%, 0);
					}

					view {
						z-index: 16;
						position: relative;
						line-height: 38rpx;
						transform: scale(0.8) !important;
						font-size: 16rpx;
					}
				}
			}
		}

		.money-bag {
			padding-top: 30rpx;

			.shopTitle {
				font-size: 30rpx;
				font-weight: bold;
			}

			.money-bag-image {
				width: 100%;
				height: 126rpx;
				position: absolute;
			}

			.money-bag-content {
				position: relative;
				padding: 0 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 126rpx;

				.money-content-left {
					color: #FFF;

					view {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						padding: 4rpx 0;

						image {
							vertical-align: middle;
							margin-right: 10rpx;
							width: 34rpx;
							height: 34rpx;
						}
					}
				}
			}
		}

		.small-assistant {
			width: 100%;
			background-color: #fff;
			border-radius: 24rpx;
			margin-top: 30rpx;
			padding: 20rpx 30rpx;

			.assistant-content {
				padding-top: 40rpx;
				display: grid;
				grid-template-columns: repeat(4, 1fr);
				gap: 10px;
				place-items: center;
				width: 100%;

				.assistant-item {
					width: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					text-align: center;
					margin-bottom: 20rpx;

					image {
						width: 58rpx;
						height: 58rpx;
					}

					.assistant-item-title {
						font-size: 24rpx;
						padding-top: 6rpx;
					}
				}
			}
		}
	}
</style>